package cn.ycc1.baseset.classes.interfaces;

/**
 * Interfaces
 * @author ycc
 * @date 2025/3/5
 */
public class Interfaces {
    /**
     * Interfaces in Java
     * There are a number of situations in software engineering when it is important for disparate groups of programmers to agree
     * to a "contract" that spells out how their software interacts. Each group should be able to write their code without any
     * knowledge of how the other group's code is written. Generally speaking, interfaces are such contracts.
     *
     * For example, imagine a futuristic society where computer-controlled robotic cars transport passengers through city streets
     * without a human operator. Automobile manufacturers write software (Java, of course) that operates the automobile—stop,
     * start, accelerate, turn left, and so forth. Another industrial group, electronic guidance instrument manufacturers,
     * make computer systems that receive GPS (Global Positioning System) position data and wireless transmission of traffic
     * conditions and use that information to drive the car.
     *
     * The auto manufacturers must publish an industry-standard interface that spells out in detail what methods can be invoked
     * to make the car move (any car, from any manufacturer). The guidance manufacturers can then write software that invokes
     * the methods described in the interface to command the car. Neither industrial group needs to know how the other group's
     * software is implemented. In fact, each group considers its software highly proprietary and reserves the right to modify
     * it at any time, as long as it continues to adhere to the published interface.
     *
     * In the Java programming language, an interface is a reference type, similar to a class, that can contain only constants,
     * method signatures, default methods, static methods (private or public, not protected), instance non-abstract methods
     * (private, not public, not protected), and nested types. Method bodies exist only for default methods, private methods
     * and static methods. Interfaces cannot be instantiated—they can only be implemented by classes or extended by other
     * interfaces. Extension is discussed later in this section.
     *
     * Defining an interface is similar to creating a new class:
     */
    public interface OperateCar {

        // constant declarations, if any

        // method signatures

        // An enum with values RIGHT, LEFT
        int turn(Direction direction,
                 double radius,
                 double startSpeed,
                 double endSpeed);
        int changeLanes(Direction direction,
                        double startSpeed,
                        double endSpeed);
        int signalTurn(Direction direction,
                       boolean signalOn);
        int getRadarFront(double distanceToCar,
                          double speedOfCar);
        int getRadarRear(double distanceToCar,
                         double speedOfCar);
         // ......
        // more method signatures
    }
    /**
     * Note that the method signatures have no braces and are terminated with a semicolon.
     *
     * To use an interface, you write a class that implements the interface. When an instantiable class implements an interface,
     * it provides a method body for each of the methods declared in the interface. For example,
     *
     * public class OperateBMW760i implements OperateCar {
     *
     *     // the OperateCar method signatures, with implementation --
     *     // for example:
     *     public int signalTurn(Direction direction, boolean signalOn) {
     *        // code to turn BMW's LEFT turn indicator lights on
     *        // code to turn BMW's LEFT turn indicator lights off
     *        // code to turn BMW's RIGHT turn indicator lights on
     *        // code to turn BMW's RIGHT turn indicator lights off
     *     }
     *
     *     // other members, as needed -- for example, helper classes not
     *     // visible to clients of the interface
     * }
     * In the robotic car example above, it is the automobile manufacturers who will implement the interface. Chevrolet's
     * implementation will be substantially different from that of Toyota, of course, but both manufacturers will adhere to the
     * same interface. The guidance manufacturers, who are the clients of the interface, will build systems that use GPS data
     * on a car's location, digital street maps, and traffic data to drive the car. In so doing, the guidance systems will
     * invoke the interface methods: turn, change lanes, brake, accelerate, and so forth.
     */

    /**
     * Interfaces as APIs
     * The robotic car example shows an interface being used as an industry standard Application Programming Interface (API).
     * APIs are also common in commercial software products. Typically, a company sells a software package that contains complex
     * methods that another company wants to use in its own software product. An example would be a package of digital image
     * processing methods that are sold to companies making end-user graphics programs:
     *
     * The image processing company writes its classes to implement an interface, which it makes public to its customers.
     * The graphics company then invokes the image processing methods using the signatures and return types defined in the
     * interface.
     * While the image processing company's API is made public (to its customers), its implementation of the API is kept as a
     * closely guarded secret—in fact, it may revise the implementation at a later date as long as it continues to implement
     * the original interface that its customers have relied on. Interfaces are versatile reference types allowing you to define
     * default methods and add functionality to a given type without breaking the implementing classes. Moreover,
     * sometimes you can factor out common bits of code in private methods, thus reducing code duplication in default methods.
     * Checkout next tutorial in this series to find out more about methods definition inside an interface.
     *
     * 机器人汽车示例显示了一个用作行业标准应用程序编程接口（API）的接口。API在商业软件产品中也很常见。通常，一家公司销售的软件包包含另一家公司
     * 希望在其自己的软件产品中使用的复杂方法。一个例子是出售给制作最终用户图形程序的公司的一套数字图像处理方法：
     * 这家图像处理公司编写类来实现一个接口，并向客户公开。
     * 然后，图形公司使用接口中定义的签名和返回类型调用图像处理方法。
     * 虽然图像处理公司的API是公开的（对其客户），但其API的实现被严格保密。事实上，只要它继续实现其客户所依赖的原始接口，它可能会在以后修改实现。
     * 接口是多用途的引用类型，允许您定义默认方法并在不破坏实现类的情况下向给定类型添加功能。此外，有时您可以排除私有方法中的公共代码位，
     * 从而减少默认方法中的代码重复。查看本系列的下一个教程，了解更多关于接口内方法定义的信息。
     */

    /**
     * Defining an Interface
     * An interface declaration consists of modifiers, the keyword interface, the interface name, a comma-separated list of parent interfaces (if any), and the interface body. For example:
     *
     * public interface GroupedInterface extends Interface1, Interface2, Interface3 {
     *
     *     // constant declarations
     *
     *     // base of natural logarithms
     *     double E = 2.718282;
     *
     *     // method signatures
     *     void doSomething (int i, double x);
     *     int doSomethingElse(String s);
     * }
     * The public access specifier indicates that the interface can be used by any class in any package. If you do not specify
     * that the interface is public, then your interface is accessible only to classes defined in the same package as the
     * interface.
     *
     * An interface can extend other interfaces, just as a class subclass or extend another class. However, whereas a class can
     * extend only one other class, an interface can extend any number of interfaces. The interface declaration includes a
     * comma-separated list of all the interfaces that it extends.
     *
     * The interface body can contain abstract methods, default methods, and static methods.
     *
     * An abstract method within an interface is followed by a semicolon, but no braces (an abstract method does not contain an
     * implementation).
     *
     * Default methods are defined with the default modifier, and static methods with the static keyword. All abstract, default,
     * and static methods in an interface are implicitly public, so you can omit the public modifier.
     *
     * In addition, an interface can contain constant declarations. All constant values defined in an interface are implicitly
     * public, static, and final. Once again, you can omit these modifiers.
     */
//    public interface GroupedInterface extends Interface1, Interface2, Interface3 {
//
//        // constant declarations
//
//        // base of natural logarithms
//        double E = 2.718282;
//
//        // method signatures
//        void doSomething (int i, double x);
//        int doSomethingElse(String s);
//    }

}
